鱼泡建筑网,优化防疫措施+科学精准防控,wordpress图片专辑,如何做网站在网上销售前言
Godot 里面C#和GDScirpt 的用法完全不一样#xff0c;网上相关资料太少了。
什么是信号
信号分为信号源#xff0c;触发#xff0c;目的节点。信号源在某些条件下触发信号#xff0c;比如按钮点击#xff0c;鼠标悬停等事件 #mermaid-svg-wyr9ARVcBFmUUu8y {font-…前言
Godot 里面C#和GDScirpt 的用法完全不一样网上相关资料太少了。
什么是信号
信号分为信号源触发目的节点。信号源在某些条件下触发信号比如按钮点击鼠标悬停等事件 #mermaid-svg-wyr9ARVcBFmUUu8y {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-wyr9ARVcBFmUUu8y .error-icon{fill:#552222;}#mermaid-svg-wyr9ARVcBFmUUu8y .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-wyr9ARVcBFmUUu8y .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-wyr9ARVcBFmUUu8y .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-wyr9ARVcBFmUUu8y .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-wyr9ARVcBFmUUu8y .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-wyr9ARVcBFmUUu8y .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-wyr9ARVcBFmUUu8y .marker{fill:#333333;stroke:#333333;}#mermaid-svg-wyr9ARVcBFmUUu8y .marker.cross{stroke:#333333;}#mermaid-svg-wyr9ARVcBFmUUu8y svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-wyr9ARVcBFmUUu8y .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-wyr9ARVcBFmUUu8y .cluster-label text{fill:#333;}#mermaid-svg-wyr9ARVcBFmUUu8y .cluster-label span{color:#333;}#mermaid-svg-wyr9ARVcBFmUUu8y .label text,#mermaid-svg-wyr9ARVcBFmUUu8y span{fill:#333;color:#333;}#mermaid-svg-wyr9ARVcBFmUUu8y .node rect,#mermaid-svg-wyr9ARVcBFmUUu8y .node circle,#mermaid-svg-wyr9ARVcBFmUUu8y .node ellipse,#mermaid-svg-wyr9ARVcBFmUUu8y .node polygon,#mermaid-svg-wyr9ARVcBFmUUu8y .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-wyr9ARVcBFmUUu8y .node .label{text-align:center;}#mermaid-svg-wyr9ARVcBFmUUu8y .node.clickable{cursor:pointer;}#mermaid-svg-wyr9ARVcBFmUUu8y .arrowheadPath{fill:#333333;}#mermaid-svg-wyr9ARVcBFmUUu8y .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-wyr9ARVcBFmUUu8y .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-wyr9ARVcBFmUUu8y .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-wyr9ARVcBFmUUu8y .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-wyr9ARVcBFmUUu8y .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-wyr9ARVcBFmUUu8y .cluster text{fill:#333;}#mermaid-svg-wyr9ARVcBFmUUu8y .cluster span{color:#333;}#mermaid-svg-wyr9ARVcBFmUUu8y div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-wyr9ARVcBFmUUu8y :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 触发 节点1 信号源:按钮点击 触发事件 节点2 新建点击事件 编写信号
我们需要编写完全一模一样的信号。如果是GDScript会自动生成对应的信号但是如果是C#的话需要我们手动添加方法
/// summary
/// 方法名必须完全一致
/// /summary
private void _on_button_pressed()
{//获取子节点LineEditvar input GetNodeLineEdit(LineEdit);//获取子节点Buttonvar button GetNodeButton(Button);//添加按钮事件button.Text $input.Text:{input.Text};}运行结果 自定义信号
delegate void 信号必须以EventHandler 结尾 [Signal]public delegate void TestEventHandler(); 自定义信号节点添加成功 信号节点自动化命名
大家可能会疑惑触发事件是自动生成的不会出问题吗一般来说不会出问题。
给别的节点传信号 给自己传信号 同名节点传信号 总结
信号命名
- 给别的节点传: _on_节点名称_方法名()
- 给自己传:_on_方法名()所以如果有两个节点名称完全一致确实会重复信号。不过Godot 限制兄弟节点是不能有同名情况出现的只能是非兄弟节点才可以。
直接获取信号
我们也可以直接在_Ready函数里面把逻辑给写了。但是只能添加默认的委托方法。此方法不推荐。一个是只能用默认方法还有一个是必须在代码里面看没有信号显示的那么直观。 public override void _Ready(){var input GetNodeLineEdit(LineEdit);var button GetNodeButton(Button);button.Pressed () {button.Text input.Text;};}